package com.secondary.action.userAction;

import java.io.ByteArrayInputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;


import com.opensymphony.xwork2.ActionContext;
@ParentPackage(value = "struts-default")
@Namespace(value = "/user")
@Action(value="random")
@Results({ 
	@Result(params={"contentType","image/jpeg","inputName","inputStream"}, type="stream")
		})
public class RandomAction {
	private ByteArrayInputStream inputStream;   
	public String execute() throws Exception{
	HttpServletRequest request = ServletActionContext.getRequest(); 
	RandomNumUtil rdnu=RandomNumUtil.Instance();      
	this.setInputStream(rdnu.getImage());
	String randomCodeName = request.getParameter("randomCodeName");
	Map codeSession = ActionContext.getContext().getSession();
	if(randomCodeName!=null&&!randomCodeName.equals("")){
		codeSession.put(randomCodeName, rdnu.getString());
	}else{
		codeSession.put("sessionCode", rdnu.getString());
	}
	return "success";      
	}      
	public void setInputStream(ByteArrayInputStream inputStream) {      
	this.inputStream = inputStream;      
	}      
	public ByteArrayInputStream getInputStream() {      
	return inputStream;      
	}     
	}   


